package day13;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by kunsb on 2016/10/17.
 */
public class FileTest {

    public static void main(String[] args) {
        File file =new File("C:\\Users\\kunsb\\Desktop");

        FileTest fileTest = new FileTest();
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("路径是：" + file.getPath());
            File[] listFiles = file.listFiles();
            fileTest.getMenu(listFiles);
            int read =scanner.nextInt();
            if (read<0|| read > listFiles.length+3){
                System.out.println("wrong");
                continue;
            }else if (read==0){
                break;
            }else if (read==1){
                String top=file.getPath().substring(0,3);
                file = new File(top);
                continue;
            }else if (read==2){
                if (file.getParentFile()!=null)
                    file =  file.getParentFile();
                continue;
            }
            File select = listFiles[read - 3];
            if (select.isDirectory()){
                file=select;
            }else {
                /*
                菜单：1.复制
                    2. 移动
                    3. 删除
                    0. 我就看看 （打印文件信息）
                 */
                System.out.println("名字："+ select.getName());
                System.out.println("长度："+ select.length() + "字节+");
            }

        }

    }
    public void getMenu(File[] file){
        System.out.println("0: 退出");
        System.out.println("1: 返回顶部");
        System.out.println("2: 返回上一层");
        for (int i = 0; i <file.length ; i++) {
            System.out.println(i+3 + ": " + file[i].getName());
        }
    }
}
